//
//  HMusicSlider.m
//  HMusicPlayer
//
//  Created by Hament on 14/9/9.
//  Copyright (c) 2014年 HJ. All rights reserved.
//

#import "HMusicSlider.h"
#import "HMusicSliderCell.h"
#import "HView.h"


@interface HMusicSlider()

- (HMusicSliderCell*)selfcell;

@property (nonatomic) BOOL mouseInside;
@property (nonatomic,strong) NSTrackingArea * trackingArea;
@end


@implementation HMusicSlider


- (void)setNeedsDisplayInRect:(NSRect)invalidRect {
    [super setNeedsDisplayInRect:[self bounds]];
}

- (id)initWithFrame:(NSRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code here.
        
    }
    return self;
}


//为音乐进度设置
-(void)SetisForDuration:(BOOL)flag{

    [self selfcell].isForDuration=flag;


}


- (HMusicSliderCell*)selfcell{

    HMusicSliderCell * thecell=(HMusicSliderCell*)[self cell];

    return  thecell;
}





- (void)drawRect:(NSRect)dirtyRect
{
    [super drawRect:dirtyRect];
    
    // Drawing code here.
}






-(void)mouseEntered:(NSEvent *)theEvent {

    //[[self selfcell].knobView setHidden:NO];

}


-(void)mouseExited:(NSEvent *)theEvent {
    
  
   // [[self selfcell].knobView setHidden:YES];
}




-(void)scrollWheel:(NSEvent *)event {

   //如果使用滑轮
    if(self.useScrollWheel){
    float delatry;
    if (delatry>5) {
        delatry=[event deltaY]/50;
    } else if (delatry>4) {
        delatry=[event deltaY]/40;
    }else if (delatry>3) {
        delatry=[event deltaY]/30;
    }else if (delatry>2) {
        delatry=[event deltaY]/20;
    } else {
     delatry=[event deltaY]/10;
    }
    debugLog(@"[event deltaY]:%f",delatry);
    [self setFloatValue:[self floatValue] - delatry];
    [self sendAction:[self action] to:[self target]];
    }
}






/*
- (void)createTrackingArea {
    
        _trackingArea = [[NSTrackingArea alloc] initWithRect:[self bounds] options:NSTrackingInVisibleRect | NSTrackingActiveInActiveApp | NSTrackingMouseEnteredAndExited owner:self userInfo:nil];
    
    [self addTrackingArea:_trackingArea];
    
    NSPoint mouseLocation = [[self window] mouseLocationOutsideOfEventStream];
    mouseLocation = [self convertPoint: mouseLocation
                              fromView: nil];
    
    if (NSPointInRect(mouseLocation, [self bounds])){
            [self mouseEntered: nil];
        }
        else
        {
            [self mouseExited: nil];
        }
    
}



//callback方法
- (void)updateTrackingAreas {

    //当控件所在的view的rect发生变化时,该方法会执行(取决于trackarea初始化时的option),所以需要删除旧的追踪区域
    [self removeTrackingArea:_trackingArea];
    [self createTrackingArea];
    [super updateTrackingAreas];
    
}
*/

@end
